layui.use(['form', 'table', 'layer', 'jquery'], function () {
    var table = layui.table,
        layer = layui.layer,
        $ = layui.jquery,
        form = layui.form;

    var tabIns = table.render({
        elem: '#empList', //绑定table id
        height: 'full-125',
        url: ctx + '/emp/list',
        page: true,
        cellMinWidth: 95, // 单元格最小宽度
        cols: [[ // 表头
            {type: 'checkbox'},
            {type: "numbers", title: '编号'}
            , {
                field: 'loginId', title: '工号', templet: function (data) {
                    return data.loginBean.account;
                }
            }
            , {field: 'empName', title: '姓名'}
            , {
                field: 'empSex', title: '性别', templet: function (data) {
                    if (data.empSex == '0') {
                        return "男"
                    } else {
                        return '女'
                    }
                }
            }
            , {field: 'empAge', title: '年龄'}
            , {field: 'empPhone', title: '联系方式'}
            , {
                field: 'empEducation', title: '学历', templet: function (data) {
                    return setEducation(data.empEducation);
                }
            }
            , {
                field: 'deptId', title: '部门', templet: function (data) {
                    return data.deptBean.deptName;
                }
            },
            {
              field: "isLeader"  , title: "岗位" ,templet:function (data){
                  if (data.isLeader =='0'){
                      return "员工"
                  }
                  if (data.isLeader == 1){
                      return  "组长"  ;
                  }
                  if (data.isLeader == 2){
                      return "总经理" ;
                  }
                }
            },
            {
                field: 'status', title: "状态", templet: function (data) {
                     if (data.empStatus == 0) {
                        return "正常"
                    } else {
                        return "离职"
                    }
                }
            }, {field: "empEntiydate", title: "入职时间"}
            , {title: '操作', templet: '#currentTableBar', fixed: 'right'}
        ]]
    });

    // 设置学历
    function setEducation(empEducation) {
        if (empEducation == '0') {
            return "中专学历";
        } else if (empEducation == '1') {
            return "大专学历";
        } else if (empEducation == '2') {
            return "本科学历";
        } else if (empEducation == "3") {
            return "硕士研究生";
        } else if (empEducation == "4") {
            return "博士研究生"
        }
        return undefined;
    }

    // 监听 行  工具栏
    table.on('tool(empFilter)', function (data) {
         if (data.event == 'edit') {
            openUpdateEmpDialog(data.data.id);
        } else if (data.event == 'delete') {
             layer.msg("离职啦")
        }
    })

    function openUpdateEmpDialog(id) {
        var url;
        if (id != null && id != '') {
            var title = "<h3>组织架构 ----  更新员工信息</h3>";
            url = ctx + "/emp/toUpdateEmpPage?id=" + id;
        } else {
            url = ctx + "/index/404"
        }
        layer.open({
            type: 2,
            title: title,
            area: ['700px', '500px'],
            content: url,
            shadeClose: true,
            maxmin: true
        })
    }
})
